//初始化
$(function(){
	search();
});


//加载页面List
function search(){
	//取条件参数
	var searchParam = JSON.stringify({
		name:$("#Name").val(),
		filename:$("#fileName").val(),
		//tags:$("#Tags").val(),
		stuts:$("#Stuts").val(),
		startTime:$("#startTime").val(),
		endTime:$("#endTime").val(),
		pageNum:$("#pageNum").val(),
		pageSize:$("#pageSize").val()
	});
	//请求Controller
	$.ajax({
        url : "/dlFocusInfo/dlFocusInfoList",
        data : searchParam,
        type : 'post',
        dataType : 'json',
        contentType : 'application/json',
        success : successFunc,
        error : errorFunc
    });
}

function successFunc(data) {

	//循环打印表格
	if(data != null){
		var list = data.pageInfo.list;//取到数据集合
		var tableList = data.thList;//	取到列表展示项List
		
		var tableHead = "";
		var innerHtml= "";
		var num = (data.pageInfo.pageNum-1)*data.pageInfo.pageSize;
		//处理列表头
//		dictContent:"标签"
//		dictId:"a5f0c4fc-9373-11e7-9ca2-28d24459a000"
//		dictName:"biaoqian"
//		dictRank:204
		tableHead += "<tr class='active'>" 
			+ "<th algin='center'><span class='entityList'>序 号</th>";
		var thList = new Array();
		$.each(tableList, function(i, row){
					var tableKey = row.dictName;
					var tabbleVal = row.dictContent;
					thList[i] = tableKey;
					tableHead += "<th algin='center'><span class='entityList'>"+tabbleVal+"</th>";
		})
		tableHead += "<th algin='center'><span class='entityList'>操 作</th>"+"</tr>";
		
		$.each(list, function(i, row){
			var id = row.fiId;
			var taglist = row.tagMap;
			
			innerHtml += "<tr <c:if test='${i%2==0}'> class='odd'</c:if>>" 
							+ "<td algin='center'><span class='entityList'>"+(num+i+1)+"</td>";
							
							for( var m = 0;m<thList.length;m++){
								var temp1 = row[thList[m]];
								if(typeof(temp1)=="undefined"){
									temp1="";
								}
								if(thList[m]=="tag"){
									temp1 = taglist["tag"];
								}
								innerHtml += "<td algin='center'><span class='entityList'>"+temp1+"</td>";
							}
			innerHtml += "<td algin='center'><span class='entityList'><a href='javascript:getInfo(\""+id+"\")' class='btn btn-primary'>查看详情</a></td>"
						+ "</tr>";
		})
		$("#tablehead").html(tableHead);
		$("#msg").html(innerHtml);
		//加载分页
		pageHelper(data.pageInfo.pageNum,data.pageInfo.lastPage);
	}else{

		alert("获取数据失败！");
	}
}
function errorFunc(data) {

	alert("获取数据失败！");
}



//查询单条详细信息，打开弹出窗
function getInfo(focusId){
	$.ajax({
        url : "/dlFocusInfo/dlFocusInfoDetail",
        data : {"focusId":focusId},
        type : 'post',
        dataType : 'json',
        success : function detailInfo(data){
        	var modalHtml = "";
        	if(data.length>0){
        		var keyList = data[0];//key集合
        		var infoList = data[1];//数据集合
        		//var dictList = data[2];//字段英——var tableKey = row.dictName;汉——var tabbleVal = row.dictContent;
        		var dictList = data[2];//英-key;汉-value
        		$.each(infoList, function(i, row){
        			for( var y = 0;y<keyList.length;y++){
        				var infoKey = keyList[y];
//        				for(var x = 0;x<dictList.length;x++){
//        					var mo = dictList[x];
//        					if(infoKey == mo.dictName){
//        						infoKey = mo.dictContent;
//        					}
//        				}
        				if(dictList[0][infoKey]){
        					infoKey = dictList[0][infoKey];
        				}
        				var infoVal = row[keyList[y]];
        				modalHtml += "<div class='form-group'>"
			  			+"<label class='control-label col-sm-2'>"+infoKey+"</label>"
			  			+"<div class='col-sm-4'>"
				  			+"<input class='form-control' id='"+infoKey+"'  name='"+infoKey+"' value='"+infoVal+"' readonly='readonly' />"
			  			+"</div>"
			  		+"</div>";
        			}
						
        		})
        	}
        	$("#modalHtml").html(modalHtml);
        	$('#focusInfo').modal();//显示模态窗口
        },
        error : errorFunc
    });
}
function createTask(){
	$.ajax({
        url : "/dlFocusInfo/dlFocusInfoCreateTask",
        type : 'post',
        success:function(data){
        	console.log(data)
        	layui.use('layer', function(){
      		  var layer = layui.layer;
      		  layer.alert(' 站点生成成功！');
      		});  
        	window.location.reload();
        },
        error:function(e){
        	console.log(e);
        }
    });

}